package gdut.jmxywz.util;

import javax.servlet.http.HttpServletRequest;

import com.handsome.ip.IPSeeker;

import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;



public class InfoIp {

	@SuppressWarnings("deprecation")
	public String getIpAddr(HttpServletRequest request ) {     
    	String ip = request.getHeader("x-forwarded-for");     
	      if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
	         ip = request.getHeader("Proxy-Client-IP");     
	     }     
	      if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
	         ip = request.getHeader("WL-Proxy-Client-IP");     
	      }     
	     if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
	          ip = request.getRemoteAddr();     
	     }    
	     System.out.println(ip);
	     return ip;     
	}   
	// ��ȡ����
	@SuppressWarnings("deprecation")
	public String getAddress(){
		WebContext context = WebContextFactory.get();
    	HttpServletRequest request = context.getHttpServletRequest();
    	String file = request.getRealPath("");
    	System.out.println(file);
    	String area=null;
		String ipAddr = getIpAddr(request);
		IPSeeker ip=new IPSeeker("QQWry.Dat",file+"\\ipdata"); 
		@SuppressWarnings("unused")
		String address = ip.getIPLocation(ipAddr).getCountry();
		area = ip.getIPLocation(ipAddr).getArea();
		return area;
	}
}
